package videoExercises;

import java.util.ArrayList;

public class AnimalTest {
    public static void main(String[] args) {
        System.out.println("能养所有的狗，但不能传递其他类型");
        ArrayList<Dog>list =new ArrayList<>();
        list.add(new Teddy("花花",1));
        //list.add(new TanukiCat("豆豆",2));
        list.add(new Huskies("小黑",3));
        //list.add(new PersianCat("小绿",4));
        keepPet1(list);
System.out.println("======================");
        System.out.println("能养所有的猫，但不能传递其他类型");
        ArrayList<Cat>list1 =new ArrayList<>();
        list1.add(new TanukiCat("豆豆",2));
        list1.add(new PersianCat("小绿",4));
        keepPet2(list1);
        System.out.println("======================");
        System.out.println("能养所有的动物，但不能传递其他类型");
        ArrayList<Animal>list2 =new ArrayList<>();
        list2.add(new Teddy("花花",1));
        list2.add(new TanukiCat("豆豆",2));
        list2.add(new Huskies("小黑",3));
        list2.add(new PersianCat("小绿",4));
        keepPet3(list2);

    }
    public static void keepPet1(ArrayList<? extends Dog>list){
        for (Animal animal : list) {
            animal.eat();
        }
    }
    public static void keepPet2(ArrayList<? extends Cat>list){
        for (Animal animal : list) {
            animal.eat();
        }
    }
    public static void keepPet3(ArrayList<? extends Animal>list){
        for (Animal animal : list) {
            animal.eat();
        }
    }
}
